package cn.zdsoft.configuration.action;

import cn.zdsoft.configuration.entity.JsonData;
import cn.zdsoft.configuration.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by wangdongdong on 2018/5/25 16:25.
 */
@RequestMapping("/conf/login")
@Controller
public class LoginAction {

    @RequestMapping("/index")
    public String index(){
        return "login/login";
    }

    @RequestMapping("/doLogin")
    @ResponseBody
    public Object doLogin(User user, HttpServletRequest request){
        if (user.isLoginSuccess()) {
            request.getSession().setAttribute("user", user);
            return JsonData.success("登陆成功");
        }
        return JsonData.fail("用户名或密码错误");
    }

    @RequestMapping("/loginOut")
    public String loginOut(HttpServletRequest request){
        request.getSession().invalidate();
        return "login/login";
    }

}
